package com.wind.lambda;

/**
 * Lambda表达式 构造方法的引用
 *
 * @author Wind
 */
public class LambdaTest04 {
    public static void main(String[] args) {
        // 使用无参构造器来引用 1
        ItemCreatorBlackConstruct construct1 = () -> new Item();
        Item item1 = construct1.getItem();
        // 使用无参构造器来引用 2
        ItemCreatorBlackConstruct construct2 = Item::new;
        Item item2 = construct2.getItem();

        // 有参的构造方法
        ItemCreatorParamContruct contruct3 = Item::new;
        Item item3 = contruct3.getItem(1, "张三", 12.3);
    }
}


@FunctionalInterface
interface ItemCreatorBlackConstruct {
    Item getItem();
}

@FunctionalInterface
interface ItemCreatorParamContruct {
    Item getItem(int id, String name, double price);
}

class Item {

    int id;
    String name;
    double price;

    public Item() {

    }

    public Item(int id, String name, double price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }
}